JavaScript Source

Visitor's clock

In Russian
По русски



Main Page

Software

Delphi

Perl

JavaScript

Sponsors

Favourites

Gouestbook

About

Rated by PING
Rambler's Top100 Service

Click here to visit our sponsor
Free Advertising from Click2Net!

In this section there are two examples of Java Script, that demonstrate showing the local time of the visitor:

Output of time on HTML page:

Example:

Code in HTML header (before </head>):

<script language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;
var id,pause=0,position=0;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + hours
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

function startclock () {
stopclock();
showtime();
} //-->
</script>

Code in page body:

<body onLoad="startclock()">
<form name="clock" onSubmit="0">
<input type="text" name="face" size=13 value="">
</form>


Time output in the StatusLine of browser:

You can see an example in the StatusLine of your browser.

Code in HTML header (before </head>):

<script Language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;

function stopclock(){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

function startclock() {
stopclock();
showtime();
}

function showtime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()

var timeValue = "Current time: " + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."

window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
//-->
</script>

In <body> tag it is necessary to add the starting clock function:

<body onLoad="startclock()">



Check E-mail
Pushing button
Visitor's clock
Format C:
Frame Destroyer
Computer name
Custom link
Following mouse
SendMail without CGI
Dynamic Graphics
Dodge of the thieves
You can always examine the HTML code of this or any other page and extract any scripts you find interesting. ;-)

PING Banner Network